



    <template>
    <div :style="{margin: '0 auto',width:'100%'}">
    <el-row :gutter="15" class="">
    <el-form ref="formRef" :model="dataForm" :rules="dataRule" size="small" label-width="100px" label-position="right"  :disabled="setting.readonly" >
    <template v-if="!loading && formOperates">
        <!-- 具体表单 -->
        <el-col :span="24"  v-if="judgeShow('title')" >
        <jnpf-form-tip-item
 label="发文标题"  v-if="judgeShow('title')"              align="left"
 prop="title" >
        <JnpfInput   v-model="dataForm.title" @change="changeData('title',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('title')"  clearable  :style='{"width":"100%"}' :maskConfig = "maskConfig.title" :showCount = "false" >
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('issuednum')" >
        <jnpf-form-tip-item
 label="发文字号"  v-if="judgeShow('issuednum')"              align="left"
 prop="issuednum" >
        <JnpfInput   v-model="dataForm.issuednum" @change="changeData('issuednum',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('issuednum')"  clearable  :style='{"width":"100%"}' :maskConfig = "maskConfig.issuednum" :showCount = "false" >
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('hostunit')" >
        <jnpf-form-tip-item
 label="主办单位"  v-if="judgeShow('hostunit')"              align="left"
 prop="hostunit" >
        <JnpfOrganizeSelect   v-model="dataForm.hostunit" @change="changeData('hostunit',-1)" 
 placeholder="请选择"  selectType="all"  :ableIds="ableAll.hostunitableIds"  :disabled="judgeWrite('hostunit')"  clearable  :style='{"width":"100%"}' :filterable = 'false' >
    </JnpfOrganizeSelect>
    </jnpf-form-tip-item>
        </el-col>

        <el-col :span="24"  v-if="judgeShow('writingdate')" >
        <jnpf-form-tip-item
 label="发文日期"  v-if="judgeShow('writingdate')"              align="left"
 prop="writingdate" >
        <JnpfDatePicker   v-model="dataForm.writingdate" @change="changeData('writingdate',-1)" 
 :startTime="dateTime(false,1,1,'','')"  :endTime="dateTime(false,1,1,'','')"  placeholder="请选择"  :disabled="judgeWrite('writingdate')"  clearable  :style='{"width":"100%"}' type="date"  format="yyyy-MM-dd" >
    </JnpfDatePicker>
    </jnpf-form-tip-item>
        </el-col>
        <!-- 表单结束 -->
    </template>
    <SelectDialog v-if="selectDialogVisible" :config="currTableConf" :formData="dataForm"
                  ref="selectDialog" @select="addForSelect" @close="selectDialogVisible=false"/>
    </el-form>
    </el-row>
    <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
    </template>

<script>
    import request from '@/utils/request'
    import {mapGetters} from "vuex";
    import {getFormById} from '@/api/workFlow/FormDesign'
    import comMixin from '@/views/workFlow/workFlowForm/mixin';
    import { getDataInterfaceRes } from '@/api/systemData/dataInterface'
    import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
    import { getDefaultCurrentValueUserId } from '@/api/permission/user'
    import { getDefaultCurrentValueDepartmentId } from '@/api/permission/organize'
    import { getDateDay, getLaterData, getBeforeData, getBeforeTime, getLaterTime } from '@/components/Generator/utils/index.js'
    import { thousandsFormat } from "@/components/Generator/utils/index"
    import SelectDialog from '@/components/SelectDialog'

    export default {
        mixins: [comMixin],
        components: { SelectDialog },
        props: [],
        data() {
        return {
            dataFormSubmitType: 0,
            continueBtnLoading: false,
            index: 0,
            prevDis: false,
            nextDis: false,
            allList: [],
            visible: false,
            loading: false,
            btnLoading: false,
            formRef: 'formRef',
            setting:{},
            eventType: '',
            userBoxVisible:false,
            selectDialogVisible: false,
            currTableConf:{},
            dataValueAll:{},
            addTableConf:{
            },
            //可选范围默认值
            ableAll:{
            },
            tableRows:{
        },
            Vmodel:"",
            currVmodel:"",
            dataForm: {
                                title : undefined,
                                issuednum : undefined,
                                    hostunit : [],
                                writingdate : undefined,
            },
            tableRequiredData: {},
            dataRule:
            {
            },
            childIndex:-1,
            interfaceRes: {
                        title:[] ,
                        issuednum:[] ,
                        hostunit:[] ,
                        writingdate:[] ,
        },
            //掩码配置
            maskConfig: {
                            title: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
                            issuednum: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
                },
            //定位属性
            locationScope: {
                },
            }
        },
        computed: {
            formOperates() {
                return this.setting.formOperates
            },


        },
        watch: {},
        created() {
            this.getFormById()
            if(this.dataForm.id == null || this.dataForm.id == '' && this.dataForm.id == undefined || this.dataForm.id == 0) {
                this.initDefaultData()
            }
            this.dataValueAll = JSON.parse(JSON.stringify(this.dataForm))
        },
        mounted() {},
        methods: {
            changeData(model, index) {
                this.childIndex = index
                let modelAll = model.split("-");
                let faceMode = "";
                for (let i = 0; i < modelAll.length; i++) {
                    faceMode += modelAll[i];
                }
                for (let key in this.interfaceRes) {
                    if (key != faceMode) {
                        let faceReList = this.interfaceRes[key]
                        for (let i = 0; i < faceReList.length; i++) {
                            if (faceReList[i].relationField == model) {
                                let options = 'get' + key + 'Options';
                                if(this[options]){
                                    this[options](true)
                                }
                                this.changeData(key, index)
                            }
                        }
                    }
                }
            },
            changeDataFormData(type, data, model,index,defaultValue) {
                if (type == 2) {
                    for (let i = 0; i < this.dataForm[data].length; i++) {
                        if (index == -1) {
                            this.dataForm[data][i][model] = defaultValue
                        } else if (index == i) {
                            this.dataForm[data][i][model] = defaultValue
                        }
                    }
                } else {
                    this.dataForm[data] = defaultValue
                }
            },
            dataAll(){
            },
            selfGetInfo(dataForm) {
                this.dataInfo(dataForm)
            },
            beforeSubmit(){
                const _data =this.dataList()
                return _data
            },
            selfInit() {
                this.dataAll()
            },
            getFormById() {
                getFormById("567263218888631749").then(res => {
                    this.dataForm.flowId = res.data&&res.data.flowId
                    // this.encode = res.data&&res.data.encode
                })
            },
            exist() {
                let isOk = true
                for (let key in this.tableRequiredData) {
                    if (this.dataForm[key] && Array.isArray(this.dataForm[key])) {
                        for (let i = 0; i < this.dataForm[key].length; i++) {
                            let item = this.dataForm[key][i]
                            inner: for (let id in item) {
                                let arr = this.tableRequiredData[key].filter(o => o.id === id) || []
                                if (!arr.length) continue inner
                                if (arr[0].required) {
                                    let msg = `${arr[0].name}不能为空`
                                    let boo = true
                                    if (arr[0].dataType === 'array') {
                                        boo = !this.jnpf.isEmptyArray(item[id])
                                    } else {
                                        boo = !this.jnpf.isEmpty(item[id])
                                    }
                                    if (!boo) {
                                        this.$message({
                                            message: msg,
                                            type: 'error',
                                            duration: 1000
                                        })
                                        isOk = false
                                        break
                                    }
                                }
                            }
                        }
                    }
                }
                    return isOk
                },
            clearData(){
                this.dataForm = JSON.parse(JSON.stringify(this.dataValueAll))


            },
            //初始化默认数据
            initDefaultData() {

            },
            openSelectDialog(key,value) {
                this.currTableConf=this.addTableConf[key + value]
                this.currVmodel=key
                this.selectDialogVisible = true
                this.$nextTick(() => {
                    this.$refs.selectDialog.init()
                })
            },
            addForSelect(data) {
                this.closeForSelect()
                for (let i = 0; i < data.length; i++) {
                    let t = data[i]
                    if(this['get'+this.currVmodel]){
                        this['get'+this.currVmodel](t,true)
                    }
                }
            },
            closeForSelect() {
                this.selectDialogVisible = false
            },
            dateTime(timeRule, timeType, timeTarget, timeValueData, dataValue) {
                let timeDataValue = null;
                let timeValue = Number(timeValueData)
                if (timeRule) {
                    if (timeType == 1) {
                        timeDataValue = timeValue
                    } else if (timeType == 2) {
                        timeDataValue = dataValue
                    } else if (timeType == 3) {
                        timeDataValue = new Date().getTime()
                    } else if (timeType == 4) {
                        let previousDate = '';
                        if (timeTarget == 1 || timeTarget == 2) {
                            previousDate = getDateDay(timeTarget, timeType, timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else if (timeTarget == 3) {
                            previousDate = getBeforeData(timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else {
                            timeDataValue = getBeforeTime(timeTarget, timeValue).getTime()
                        }
                    } else if (timeType == 5) {
                        let previousDate = '';
                        if (timeTarget == 1 || timeTarget == 2) {
                            previousDate = getDateDay(timeTarget, timeType, timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else if (timeTarget == 3) {
                            previousDate = getLaterData(timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else {
                            timeDataValue = getLaterTime(timeTarget, timeValue).getTime()
                        }
                    }
                }
                return timeDataValue;
            },
            time(timeRule, timeType, timeTarget, timeValue, formatType, dataValue) {
                let format = formatType == 'HH:mm' ? 'HH:mm:00' : formatType
                let timeDataValue = null
                if (timeRule) {
                    if (timeType == 1) {
                        timeDataValue = timeValue || '00:00:00'
                        if (timeDataValue.split(':').length == 3) {
                            timeDataValue = timeDataValue
                        } else {
                            timeDataValue = timeDataValue + ':00'
                        }
                    } else if (timeType == 2) {
                        timeDataValue = dataValue
                    } else if (timeType == 3) {
                        timeDataValue = this.jnpf.toDate(new Date(), format)
                    } else if (timeType == 4) {
                        let previousDate = '';
                        previousDate = getBeforeTime(timeTarget, timeValue)
                        timeDataValue = this.jnpf.toDate(previousDate, format)
                    } else if (timeType == 5) {
                        let previousDate = '';
                        previousDate = getLaterTime(timeTarget, timeValue)
                        timeDataValue = this.jnpf.toDate(previousDate, format)
                    }
                }
                return timeDataValue;
            },
            dataList(){
                var _data = this.dataForm;
                return _data;
            },
            dataInfo(dataAll){
                let _dataAll =dataAll
                this.dataForm = _dataAll
                this.dataAll()
                this.childIndex=-1
            },
        },
    }

</script>
